﻿#include "DABaseFrame.h"
#include "qgridlayout.h"

#include <QGraphicsItem>
#include <QPainter>
#include <QStyleOption>
#include <QStyleOption>

DABaseFrame::DABaseFrame(QWidget *parent):
    QFrame(parent)
{
    setWindowFlag(Qt::FramelessWindowHint);
    setAttribute(Qt::WA_TranslucentBackground);
    setMouseTracking(true);
    setObjectName("DABaseFrame");
    
}

void DABaseFrame::paintEvent(QPaintEvent *e)
{
    QStyleOption opt;
    opt.initFrom(this);
    QPainter painter(this);
    style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this);

    painter.setRenderHint(QPainter::Antialiasing); // 反锯齿;
    painter.setBrush(QBrush(QColor(30, 30, 30)));//RGB+透明度
    painter.setPen(Qt::transparent);
    
//    QRect rect = this->rect();
//    rect.setWidth(this->size().width() - 1);
//    rect.setHeight(this->size().height() - 1);
//    painter.drawRoundedRect(rect, 5, 5);//圆角大小
    
    //调试用：绘制窗口边框   
//    QPen pen;
//    pen.setColor(Qt::red);
//    pen.setWidth(0);
//    painter.setPen(pen);
//    painter.drawRect(this->rect());
//    painter.end();
    
    QFrame::paintEvent(e);
}


void DABaseFrame::setPosition(QP::POSITION pos)
{
    FunTools::GetInst()->SetPosition(this,pos);
}

void DABaseFrame::setWidgetSize(int w,int h)
{
    resize(w,h);
//    setFixedSize(w,h);
}

void DABaseFrame::setWidgetHeight(int h)
{
    setFixedSize(this->width(),h);
    //    setFixedSize(w,h);
}

void DABaseFrame::setHSizePolicy(QSizePolicy::Policy hor)
{
    QSizePolicy sizePolicy1=this->sizePolicy();
    sizePolicy1.setHorizontalPolicy(hor);
    this->setSizePolicy(sizePolicy1);
}

void DABaseFrame::setVSizePolicy(QSizePolicy::Policy hor)
{
    QSizePolicy sizePolicy1=this->sizePolicy();
    sizePolicy1.setHorizontalPolicy(hor);
    this->setSizePolicy(sizePolicy1);
}

void DABaseFrame::addWdiget(QWidget *w)
{
    w->setParent(this);
    QGridLayout *grid = new QGridLayout();
    grid->addWidget(w);
    grid->setSpacing(0);
    grid->setContentsMargins(0,0,0,0);
    this->setLayout(grid);
}

void DABaseFrame::setWidgetSize(QSize size)
{
    resize(size);
//    setFixedSize(size);
}

